package t4tools.splittingObjects.order;

import java.util.Comparator;

import t4tools.splittingObjects.model.Row;

public final class Order implements Comparator<Row> {

	public static final Order DEFAULT = Order.asc(new DefaultAlphabeticalComparator());

	private boolean asc;
	private Comparator<Row> comparator;

	private Order(Comparator<Row> comparator, boolean asc) {
		this.comparator = comparator;
		this.asc = asc;
	}

	public static Order asc(Comparator<Row> comparator) {
		return new Order(comparator, true);
	}

	public static Order desc(Comparator<Row> comparator) {
		return new Order(comparator, false);
	}

	public int compare(Row o1, Row o2) {
		return asc ? comparator.compare(o1, o2) : comparator.compare(o1, o2) * -1;
	}
}
